\ Preprocessor Forth Object Oriented Simple - Copyright 2012,2013 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

\ Inspired by Mini-OOF, made by Bernd Paysan, 2008
\ WARNING! Incompatible with CLOSURES.4PP

[DEFINED] allocate [IF]
  [DEFINED] forcecellheap [IF]
    : (~~alloc) allocate abort" Out of heap space" ;
  [THEN]
[THEN]

: (~~child!) over ! ; : parent@ @ 1+ @c ;
: (~~parent!) >r over >r execute r> r> (~~child!) ;
: derived? swap begin over over <> while dup 1+ @c tuck = until = ;
:macro :: : @1@ #1# ; :macro type@ @ ; :macro typeof @1@ ['] #1# ;
:macro kindof typeof derived? ; :macro parentof typeof 1+ @c ;
:macro (.mangle) ~~ |#| ; :macro sizeof @1@ >1> (.mangle) ;
:macro class struct 1+ ; :macro extends >1> >1> sizeof ; :macro :static : ;
:macro end-class >1> end-struct (.mangle) ['] #1# (~~child!) ;
:macro method: field: ; :macro :method :noname ; :macro static: >#> <#< ;
:macro end-extends end-struct (.mangle) ['] #1# <1< ['] #1# (~~parent!) ;
:macro { >r ; :macro } r> drop ; :macro this r@ ; :macro {} drop ;
:macro defines @1@ this -> #1# ! ; :macro overrides ['] latest defines ;
:macro static sizeof array >1> @1@ #1# latest <1< #1# ;
:macro new sizeof (~~alloc) >1> @1@ dup to #1# <1< #1# ;
:macro (private) @1@ >1> >>> } @until @drop hide #1# (private) ;
:macro private{ (private) @drop ; :macro => @1@ dup #1# @ execute ;